package main

import (
	"aqchain/pkg/blockchain"
	"aqchain/pkg/config"
	"aqchain/pkg/log"
	"aqchain/pkg/model"
	"aqchain/pkg/router"
	"flag"
	"go.uber.org/zap"
	"os"
	"path"
)

func main() {
	var configFile string
	wd, _ := os.Getwd()
	flag.StringVar(&configFile, "configFile", path.Join(wd, "config1.json"), "配置文件")
	logLevel := zap.LevelFlag("logLevel", -1, "日志级别")
	flag.Parse()

	log.Init(*logLevel)
	cfg := config.New(configFile)
	db := model.New(cfg.Database)
	c := blockchain.New(cfg, db)
	r := router.New(cfg, db)

	go func() {
		err := r.Run()
		if err != nil {
			if err != nil {
				log.Logger.Panic("运行错误", zap.String("error", err.Error()))
			}
		}
	}()
	go func() {
		err := c.Run()
		if err != nil {
			if err != nil {
				log.Logger.Panic("运行错误", zap.String("error", err.Error()))
			}
		}
	}()

	select {}
}
